package di;

import di.aop.AopConfig;
import di.config.DiConfig;
import di.javaconfig.Function2Service;
import di.javaconfig.JavaConfig;
import di.service.DemoAnnotationService;
import di.service.DemoMethodService;
import di.service.FunctionService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Description: TODO
 * @Author: chris_cai@enable-ets.com
 * @Since: 2018年09月26日
 */
public class Main {

    public static void main(String[] args) {

        //1.依赖注入
        //AnnotationConfigApplicationContext作为spring的容器,需要传入一个配置类作为参数
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DiConfig.class);

        FunctionService functionService = context.getBean(FunctionService.class);

        System.out.println(functionService.say("world"));

        //2.使用Java类配置
        AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext(JavaConfig.class);

        Function2Service function2Service = context2.getBean(Function2Service.class);

        System.out.println(function2Service.say("world"));

        //AOP配置
        AnnotationConfigApplicationContext context3 = new AnnotationConfigApplicationContext(AopConfig.class);

        DemoAnnotationService demoAnnotationService = context3.getBean(DemoAnnotationService.class);

        DemoMethodService demoMethodService = context3.getBean(DemoMethodService.class);

        demoAnnotationService.add();

        demoMethodService.add();
    }
}
